<?php
$this->load->view("header2");

$na = 0;
$ioc = 0;

foreach($importance_of_customers as $name => $value){
    if(!empty($post_data["importance"]))
    if($value->value==$post_data["importance"]){    
                $ioc = $value->importance_of_customers_id;
    }    
}

foreach($nationality as $_n => $_v){
    if(!empty($post_data["nationality"]))
    if($_v->value == $post_data["nationality"]){    
                $na = $_v->nationality_id;
    }    
}

?>

<input type="hidden"  id="name" value="<?= !empty($post_data["name"])?$post_data["name"]:''; ?>" >
<input type="hidden"  id="recommended" value="<?= !empty($post_data["recommended"])?$post_data["recommended"]:''; ?>" >
<input type="hidden"  id="importance" value="<?= !empty($ioc)?$ioc:''; ?>" >
<input type="hidden"  id="nationality" value="<?= !empty($na)?$na:''; ?>" >

<div id="content">

        <link rel="stylesheet" href="<?= base_url() ?>css/crid_style.css" />
        <link rel="stylesheet" type="text/css" href="<?= base_url() ?>css/flexigrid.pack.css" />
        <script type="text/javascript" src="<?= base_url() ?>js/flexigrid.pack.js"></script>
        <script type="text/javascript" src="<?= base_url() ?>js/flexigrid2.js"></script>


        <table class="flexme4" style="display: none"></table>
        <script type="text/javascript">
               
            $(".flexme4").flexigrid({
                url : '/client/client_sf_josn',
                dataType : 'json',
                colModel : [ {
                    display : '編號',
                    name : 'client_id',
                    width : '90',
                    sortable : true,
                    align : 'center'
                    },
                    {
                        display : '姓名',
                        name : 'name',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    }, 
                    {
                        display : '公司名稱',
                        name : 'company_name',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    }, {
                        display : '手機',
                        name : 'mobile',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    }, {
                        display : '住家電話',
                        name : 'home_phone',
                        width : 100,
                        sortable : true,
                        align : 'left'//,
                        //hide : true
                    }
                    , {
                        display : '傳真',
                        name : 'fax',
                        width : 80,
                        sortable : true,
                        align : 'right'
                        }
                        , {
                        display : '重要性',
                        name : 'importance',
                        width : 60,
                        sortable : true,
                        align : 'right'
                        }, 
                        {
                        display : '住家地址',
                        name : 'home_address',
                        width : 140,
                        sortable : true,
                        align : 'right'
                        }, 
                        {
                        display : '公司地址',
                        name : 'company_address',
                        width : 140,
                        sortable : true,
                        align : 'right'
                        }, 
                        {
                        display : '經紀人',
                        name : 'broker',
                        width : 60,
                        sortable : true,
                        align : 'right'
                        }
                        ],
                buttons : [ 
                    {
                        name : '編輯',
                        bclass : 'edit',
                        onpress : Example4
                    }
                    ,
                    {
                        name : 'Excel',
                        bclass : 'coffee',
                        onpress : Example4
                    }
                    ,
                    {
                        name : '删除',
                        bclass : 'delete',
                        onpress : Example4
                    }
                    ,
                    {
                        name : 'edm',
                        bclass : 'edm',
                        onpress : Example4
                    }
                    ,
                    {
                        name : 'sms',
                        bclass : 'sms',
                        onpress : Example4
                    }
                    ,
                    {
                        separator : true
                    } 
                ],
                
                sortname : "client_id",
                sortorder : "asc",
                usepager : true,
                title : '客戶資料查詢结果',                
                useRp : true,
                checkbox : true,// 是否要多選框
                rp : 10,                
                width : 'auto',
                height : 'auto',
                procmsg:'資料讀取中，請稍後…', 
                nomsg:'找不到符合絛件的資料',                  
                
                //margin: 10px 1px 1px -53px
            });
            
            function Example4(com, grid) {


                if (com == '删除') {

                    var empty_str ='';
                    var _fg =true;
                      $(".trSelected").each(function() {

                        var str = $(this).children().next().html();
                        var str2 = str.split('</div>');
                        var str = str2[0].split('>');                    


                        if(_fg){

                          _fg = false;
                          empty_str+= parseInt(str[1]);

                        }else{

                          empty_str+= ","+parseInt(str[1]);

                        }
                    });  

                    

                    $.post('/client/save_client_id', {

                            id : empty_str ,
                            is_del : '0'

                    }, function(data) {
                            $.post('/client/delete_client', 
                                function(data) {
                                    //alert(data);
                                    $(".flexme4").flexReload();
                                });                            
                    });

                }
                else if (com == '編輯') {
                    $(".trSelected").each(function() {

                        var str = $(this).children().next().html();
                        var str2 = str.split('</div>');
                        var str = str2[0].split('>');
                        var url = '/client/data_edit/'+parseInt(str[1]);                     
                        document.location.href = url;
                    
                    });
                }
                else if (com == 'sms') {

                    $(".trSelected").each(function() {

                        var str = $(this).children().next().html();
                        var str2 = str.split('</div>');
                        var str = str2[0].split('>');
                        var url = '/send_sms/index/'+parseInt(str[1]);                     
                        document.location.href = url;
                    
                    });

                }
                else if (com == 'edm') {

                    $(".trSelected").each(function() {

                        var str = $(this).children().next().html();
                        var str2 = str.split('</div>');
                        var str = str2[0].split('>');
                        var url = '/send_edm/index/'+parseInt(str[1]);                     
                        document.location.href = url;
                    
                    });

                }                
                else if (com == 'Excel') {                     

                var empty_str ='';
                var _fg =true;
                  $(".trSelected").each(function() {

                    var str = $(this).children().next().html();
                    var str2 = str.split('</div>');
                    var str = str2[0].split('>');                    


                    if(_fg){

                      _fg = false;
                      empty_str+= parseInt(str[1]);

                    }else{

                      empty_str+= ","+parseInt(str[1]);

                    }
                });  

                

                $.post('/client/save_client_id', {

                        id : empty_str ,
                        is_del : '0'

                }, function(data) {
                        var url = '/client/excel';                
                        document.location.href = url;                                       
                });

                }
                else if (com == 'edm') { 

                    //alert('ddd');
                    $.get('/send_edm/send_edm_group_session', { 
                      
                    },function(data){
                      
                      
                    });

                }

                
            }


            function save_client(id){

                $.get('/client/get_save_client_id', { 
                    id: id
                },function(data){
                    
                  
                });

            }



        function query() {
            
           
            var name = $("#name").val();                    
            var recommended = $("#recommended").val();
            var importance = $("#importance").val();
            var nationality = $("#nationality").val();
            
            $(".flexme4").flexOptions(
                    {newp: 1, params:
                                [
                                    {name: 'name',
                                        value: name}  
                                    ,
                                    {name: 'recommended',
                                        value: recommended}      
                                    ,
                                    {name: 'importance',
                                        value: importance}
                                    ,
                                    {name: 'nationality',
                                        value: nationality}              
                                ]
                    }).flexReload();
        }

        $("document").ready(function() {

            setTimeout('query()', 200);

        });

        </script>
</div>
<?=isset($footer) ? $footer : ''?>